﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BIZ;
using System.Web.Script.Serialization;
using System.Collections;
using System.Data;
using DomainModel;
using System.IO;
using System.Text;

namespace joyAdmin.Controllers
{
    [DomainConfirmationFilter]
    [BIZ.AdminFilter]
    public class LibraryBookController : Controller
    {
        BookOper boper = new BookOper();
        UserOper userOper = new UserOper();
        UserClassOper uOper = new UserClassOper();
        LibraryBookIndentOper indentOper = new LibraryBookIndentOper();
        IndentOperationLogOper logOper = new IndentOperationLogOper();
        BorrowBooksRule bookRule = new BorrowBooksRule();
        


        //
        // GET: /LibraryBook/
        /// <summary>
        /// 新入库图书
        /// </summary>
        /// <returns></returns>
        public ActionResult putInStorage()
        {
            cmsOper.CheckUserRights("putInStorage");
            return View();
        }

        public ActionResult bookDetail()
        {
            cmsOper.CheckUserRights("bookDetail");
            return View();
        }
        /// <summary>
        /// 借出图书
        /// </summary>
        /// <returns></returns>
        public ActionResult loanBooks()
        {
            cmsOper.CheckUserRights("loanBooks");
            return View();
        }

        /// <summary>
        /// 已归还图书
        /// </summary>
        /// <returns></returns>
        public ActionResult returnBooks()
        {
            cmsOper.CheckUserRights("returnBooks");
            return View();
        }

        public JsonResult getReturnBooks()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            string bookname = Request.Form["bookname"];
            string in_s = Request.Form["in_s"];
            string in_e = Request.Form["in_e"];
            return Json(boper.getReturnBooks(bookname, in_s, in_e, pageno, pagesize));
        }

        public JsonResult getloanBooks()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            string bookname = Request.Form["bookname"];
            string in_s = Request.Form["in_s"];
            string in_e = Request.Form["in_e"];
            return Json(boper.getloanBooks(bookname, in_s, in_e, pageno, pagesize));
        }
        public ActionResult bookborrowlist()
        {
            int lbdid = Convert.ToInt32(Request["lbdid"]);
            ViewData["list"] = boper.getisbnborrowlist(lbdid);
            return View();
        }
        public JsonResult getputInStorage()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            string bookname = Request.Form["bookname"];
            string in_s = Request.Form["in_s"];
            string in_e = Request.Form["in_e"];
            return Json(boper.getputInStorage(bookname, in_s, in_e, pageno, pagesize));
        }
        public void userbooklistExce()
        {
            string uid = Request["uid"];
            DAL.Service.IUserInfoService user = new DAL.Service.Impl.UserInfoServiceImpl();
            DataTable dt = user.userBooksListTable(int.Parse(uid));
            //转换类型等为中文字
            dt.Columns.Add("clb_state");
            dt.Columns.Add("clb_forAge");
            dt.Columns.Add("clb_level");
            dt.Columns.Add("clb_bookType");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                dr["clb_forAge"] = Enum.GetName(typeof(DAL.Enums.bookforAge), int.Parse(dr["lb_forAge"].ToString())).Replace("_", "");
                dr["clb_level"] = Enum.GetName(typeof(DAL.Enums.boollevel), int.Parse(dr["lb_level"].ToString()));
                dr["clb_bookType"] = Enum.GetName(typeof(DAL.Enums.bookType), int.Parse(dr["lb_bookType"].ToString()));
                dr["clb_state"] = Enum.GetName(typeof(DAL.Enums.bookState), int.Parse(dr["lb_state"].ToString()));
            }
            BIZ.ExcelOper.ExportToExcel(dt, new string[] { "lbd_isbn", "lb_bookName", "lb_translatedName", "clb_state", "clb_forAge", "clb_level", "clb_bookType", "lbi_time", "returntime", "lbi_appraisal" }, new string[] { "ISBN", "书名", "译名", "图书状态", "适读年龄", "级别", "类型", "借阅时间", "归还时间", "家长备注" }, "会员借阅记录导出");
        }
        #region 图书管理
        public ActionResult LibraryBookManage()
        {
            cmsOper.CheckUserRights("LibraryBookManage");
            return View();
        }

        [ValidateInput(false)]
        public ActionResult saveLibraryBook()
        {
            DomainModel.LibraryBook _staff = new JavaScriptSerializer().Deserialize<DomainModel.LibraryBook>(Request.Form["LibraryBook"].ToString());
            if (_staff.lb_id == 0)
            {
                _staff.lb_addTime = DateTime.Now;
                _staff.lb_user = ((DomainModel.cmsuser)Session["cmsuser"]).id;
            }
            else
            {
                _staff.lb_updateTime = DateTime.Now;
                _staff.lb_addTime = _staff.lb_addTime.ToLocalTime();
                _staff.lb_lastUser = ((DomainModel.cmsuser)Session["cmsuser"]).id;
            }
            boper.save(_staff);
            return Json(_staff);
        }
        /// <param name="bookName">书名</param>
        /// <param name="translatedName">译名</param>
        /// <param name="language">语种</param>
        /// <param name="ebook">电子或图书</param>
        /// <param name="forAge">适读年龄</param>
        /// <param name="level">级别</param>
        /// <param name="bookType">类型</param>
        /// <param name="bookTheme">主题</param>
        /// <param name="author">作者</param>
        /// <param name="press">出版社</param>
        /// <param name="in_s">添加时间结束</param>
        /// <param name="in_e">添加时间开始</param>
        /// <param name="pageno">页码</param>
        /// <param name="pagesize">每页条数</param>
        public JsonResult getLibraryBookist()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            string bookName = Request.Form["bookName"];
            string translatedName = Request.Form["translatedName"];
            int language = int.Parse(Request.Form["language"]);
            int ebook =  int.Parse(Request.Form["ebook"]);
            int forAge =  int.Parse(Request.Form["forAge"]);
            int level =  int.Parse(Request.Form["level"]);
            int bookType = int.Parse(Request.Form["bookType"]);
            int bookTheme =  int.Parse(Request.Form["bookTheme"]);
            int state = int.Parse(Request.Form["state"]);
            string author = Request.Form["author"];
            string press = Request.Form["press"];            
            string in_s = Request.Form["in_s"];
            string in_e = Request.Form["in_e"];
            string isbn = Request.Form["isbn"];
            string selbookaboutcd = Request.Form["selbookaboutcd"];
            string txtbookcount = Request.Form["txtbookcount"];
            string txtbooksum = Request.Form["txtbooksum"];
            string txtbsum = Request.Form["txtbsum"];
            string txtwhere = Request.Form["txtwhere"];
            string txtjiage = Request.Form["txtjiage"];


            string olb_bookName = Request.Form["olb_bookName"];
            string olb_ebook = Request.Form["olb_ebook"];
            string olb_forAge = Request.Form["olb_forAge"];
            string olb_level = Request.Form["olb_level"];
            string olb_bookType = Request.Form["olb_bookType"];
            string olb_bookTheme = Request.Form["olb_bookTheme"];
            string olb_booksCount = Request.Form["olb_booksCount"];
            string olb_inventory = Request.Form["olb_inventory"];
            string olb_position = Request.Form["olb_position"];
            string olb_price = Request.Form["olb_price"];
            string olb_state = Request.Form["olb_state"];
            string olb_id = Request.Form["olb_id"];

            return Json(boper.getLibraryBookist(bookName,
                translatedName,
                language,
                ebook,
                forAge,
                level,
                bookType,
                bookTheme,
                author,
                press,                
                in_s, 
                in_e,
                state,
                pageno,
                pagesize, isbn, selbookaboutcd, txtbookcount, txtbooksum, txtbsum, txtwhere, txtjiage, olb_bookName, olb_ebook, olb_forAge, olb_level, olb_bookType, olb_bookTheme, olb_booksCount, olb_inventory, olb_position, olb_price, olb_state, olb_id));
        }

        public JsonResult getBookDetaillist()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            string bookName = Request.Form["bookName"];
            string translatedName = Request.Form["translatedName"];
            int language = int.Parse(Request.Form["language"]);
            int ebook = int.Parse(Request.Form["ebook"]);
            int forAge = int.Parse(Request.Form["forAge"]);
            int level = int.Parse(Request.Form["level"]);
            int bookType = int.Parse(Request.Form["bookType"]);
            int bookTheme = int.Parse(Request.Form["bookTheme"]);
            int state = int.Parse(Request.Form["state"]);
            string author = Request.Form["author"];
            string press = Request.Form["press"];
            string in_s = Request.Form["in_s"];
            string in_e = Request.Form["in_e"];
            string isbn = Request.Form["isbn"];
            string selbookaboutcd = Request.Form["selbookaboutcd"];
            string txtwhere = Request.Form["txtwhere"];
            string txtjiage = Request.Form["txtjiage"];


            string olb_bookName = Request.Form["olb_bookName"];
            string olb_ebook = Request.Form["olb_ebook"];
            string olb_forAge = Request.Form["olb_forAge"];
            string olb_level = Request.Form["olb_level"];
            string olb_bookType = Request.Form["olb_bookType"];
            string olb_bookTheme = Request.Form["olb_bookTheme"];
            string olb_state = Request.Form["olb_state"];
            string olb_id = Request.Form["olb_id"];
            string olbd_isbn = Request.Form["olbd_isbn"];
            string olb_translatedName = Request.Form["olb_translatedName"];
            string olb_language = Request.Form["olb_language"];
            string jc_s = Request.Form["jc_s"];
            string jc_e = Request.Form["jc_e"];
            string gh_s = Request.Form["gh_s"];
            string gh_e = Request.Form["gh_e"];
            string selmp3 = Request.Form["selmp3"];

            return Json(boper.getBookDetaillist(bookName,
                translatedName,
                language,
                ebook,
                forAge,
                level,
                bookType,
                bookTheme,
                author,
                press,
                in_s,
                in_e,
                state,
                pageno,
                pagesize, isbn, selbookaboutcd, txtwhere, txtjiage, olb_bookName, olb_ebook, olb_forAge, olb_level, olb_bookType, olb_bookTheme, olb_state, olb_id, olbd_isbn, olb_translatedName, olb_language, jc_s, jc_e, gh_s, gh_e, selmp3));
        }
        public void getBookDetaillistExcel()
        {
            int pageno = 1;
            int pagesize = 20000;
            string bookName = Request["bookName"];
            string translatedName = Request["translatedName"];
            int language = int.Parse(Request["language"]);
            int ebook = int.Parse(Request["ebook"]);
            int forAge = int.Parse(Request["forAge"]);
            int level = int.Parse(Request["level"]);
            int bookType = int.Parse(Request["bookType"]);
            int bookTheme = int.Parse(Request["bookTheme"]);
            int state = int.Parse(Request["state"]);
            string author = Request["author"];
            string press = Request["press"];
            string in_s = Request["in_s"];
            string in_e = Request["in_e"];
            string isbn = Request["isbn"];
            string selbookaboutcd = Request["selbookaboutcd"];
            string txtwhere = Request["txtwhere"];
            string txtjiage = Request["txtjiage"];


            string olb_bookName = Request["olb_bookName"];
            string olb_ebook = Request["olb_ebook"];
            string olb_forAge = Request["olb_forAge"];
            string olb_level = Request["olb_level"];
            string olb_bookType = Request["olb_bookType"];
            string olb_bookTheme = Request["olb_bookTheme"];
            string olb_state = Request["olb_state"];
            string olb_id = Request["olb_id"];
            string olbd_isbn = Request["olbd_isbn"];
            string olb_translatedName = Request["olb_translatedName"];
            string olb_language = Request["olb_language"];
            string jc_s = Request["jc_s"];
            string jc_e = Request["jc_e"];
            string gh_s = Request["gh_s"];
            string gh_e = Request["gh_e"];
            string selmp3 = Request["selmp3"];

            System.Data.DataTable dt = new System.Data.DataTable();
            DAL.Service.IBookService b = new DAL.Service.Impl.BookServiceImpl();
            dt = b.getBookDetaillistDatatable(bookName,
                translatedName,
                language,
                ebook,
                forAge,
                level,
                bookType,
                bookTheme,
                author,
                press,
                in_s,
                in_e,
                state,
                pageno,
                pagesize, isbn, selbookaboutcd, txtwhere, txtjiage, olb_bookName, olb_ebook, olb_forAge, olb_level, olb_bookType, olb_bookTheme, olb_state, olb_id, olbd_isbn, olb_translatedName, olb_language, jc_s, jc_e, gh_s, gh_e, selmp3);

            //转换类型等为中文字
            dt.Columns.Add("clbd_state");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                dr["clbd_state"] = Enum.GetName(typeof(DAL.Enums.isbnstate), int.Parse(dr["lbd_state"].ToString()));
            }
            BIZ.ExcelOper.ExportToExcel(dt, new string[] { "lbd_isbn", "lb_bookName", "lb_translatedName", "clbd_state" }, new string[] { "ISBN", "书名", "译名", "在馆状态" }, "图书查询功能导出");
        }
        public void booklistExce()
        {
            int pageno = 1;
            int pagesize = 20000;
            string bookName = Request["bookName"];
            string translatedName = Request["translatedName"];
            int language = int.Parse(Request["language"]);
            int ebook = int.Parse(Request["ebook"]);
            int forAge = int.Parse(Request["forAge"]);
            int level = int.Parse(Request["level"]);
            int bookType = int.Parse(Request["bookType"]);
            int bookTheme = int.Parse(Request["bookTheme"]);
            int state = int.Parse(Request["state"]);
            string author = Request["author"];
            string press = Request["press"];
            string in_s = Request["in_s"];
            string in_e = Request["in_e"];
            string isbn = Request["isbn"];
            string selbookaboutcd = Request["selbookaboutcd"];
            string txtbookcount = Request["txtbookcount"];
            string txtbooksum = Request["txtbooksum"];
            string txtbsum = Request["txtbsum"];
            string txtwhere = Request["txtwhere"];
            string txtjiage = Request["txtjiage"];


            string olb_bookName = Request["olb_bookName"];
            string olb_ebook = Request["olb_ebook"];
            string olb_forAge = Request["olb_forAge"];
            string olb_level = Request["olb_level"];
            string olb_bookType = Request["olb_bookType"];
            string olb_bookTheme = Request["olb_bookTheme"];
            string olb_booksCount = Request["olb_booksCount"];
            string olb_inventory = Request["olb_inventory"];
            string olb_position = Request["olb_position"];
            string olb_price = Request["olb_price"];
            string olb_state = Request["olb_state"];
            string olb_id = Request["olb_id"];


            System.Data.DataTable dt = new System.Data.DataTable();
            DAL.Service.IBookService b = new DAL.Service.Impl.BookServiceImpl();

            dt = b.getLibraryBookistDatatable(bookName,
                translatedName,
                language,
                ebook,
                forAge,
                level,
                bookType,
                bookTheme,
                author,
                press,
                in_s,
                in_e,
                state,
                pageno,
                pagesize, isbn, selbookaboutcd, txtbookcount, txtbooksum, txtbsum, txtwhere, txtjiage, olb_bookName, olb_ebook, olb_forAge, olb_level, olb_bookType, olb_bookTheme, olb_booksCount, olb_inventory, olb_position, olb_price, olb_state, olb_id);
            //转换类型等为中文字
            dt.Columns.Add("clb_language");
            dt.Columns.Add("clb_ebook");
            dt.Columns.Add("clb_forAge");
            dt.Columns.Add("clb_level");
            dt.Columns.Add("clb_bookType");
            dt.Columns.Add("clb_bookTheme");
            dt.Columns.Add("clb_aboutCd");
            dt.Columns.Add("clb_state");
            for (int i = 0; i < dt.Rows.Count;i++ )
            {
                DataRow dr = dt.Rows[i];
                dr["clb_language"] = Enum.GetName(typeof(DAL.Enums.booklanguage), int.Parse(dr["lb_language"].ToString()));
                dr["clb_ebook"] = Enum.GetName(typeof(DAL.Enums.bookebook), int.Parse(dr["lb_ebook"].ToString()));
                dr["clb_forAge"] = Enum.GetName(typeof(DAL.Enums.bookforAge), int.Parse(dr["lb_forAge"].ToString())).Replace("_", "");
                dr["clb_level"] = Enum.GetName(typeof(DAL.Enums.boollevel), int.Parse(dr["lb_level"].ToString()));
                dr["clb_bookType"] = Enum.GetName(typeof(DAL.Enums.bookType), int.Parse(dr["lb_bookType"].ToString()));
                dr["clb_bookTheme"] = Enum.GetName(typeof(DAL.Enums.bookTheme), int.Parse(dr["lb_bookTheme"].ToString()));
                dr["clb_aboutCd"] = Enum.GetName(typeof(DAL.Enums.bookAboutCd), int.Parse(dr["lb_aboutCd"].ToString()));
                dr["clb_state"] = Enum.GetName(typeof(DAL.Enums.bookState), int.Parse(dr["lb_state"].ToString()));
            }
            BIZ.ExcelOper.ExportToExcel(dt, new string[] { "lb_bookName", "lb_translatedName", "clb_language", "clb_ebook", "clb_forAge", "clb_level", "clb_bookType", "clb_bookTheme", "lb_author", "lb_time", "lb_pageSize", "lb_kb", "lb_bz", "clb_aboutCd", "lb_aboutMp3", "lb_bookContent", "lb_booksCount", "lb_inventory", "bbooksum", "lb_addTime", "lb_position", "lb_price", "clb_state" }, new string[] { "书名", "译名", "语种", "图书形式", "适读年龄", "级别", "类型", "主题", "作者", "出版时间", "页数", "开本", "包装", "是否有CD", "音频文件", "内容简介", "图书总量", "库存量", "借出量", "入库时间", "存放地点", "价格", "书籍状态" }, "图书管理功能导出");
        }
        public ActionResult booklist()
        {
            return View();
        }
        public JsonResult getLibraryBookbyid()
        {
            string id = Request.Form["res"];
            IList list = boper.getLibraryBookbyid(int.Parse(id));
            if (list.Count > 0)
                return Json(list[0]);
            else
                return Json("");
        }

        public JsonResult changeisbnstate()
        {
            string id = Request.Form["res"];
            return Json(boper.updateIsbnBookState(int.Parse(id), ((int)DAL.Enums.isbnstate.图书丢失)));
        }
        public ActionResult getTxtisbn()
        {
            string path = Request["path"].ToString();
            StreamReader objReader = new StreamReader(Server.MapPath(path));
            string sLine = "";
            Dictionary<string, string> dicData = new Dictionary<string, string>();
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                    if (!dicData.ContainsKey(sLine))//去除重复
                            dicData.Add(sLine, null);
            }
            objReader.Close();
            string number = string.Empty;
            foreach (string sOutput in dicData.Keys)
                number += sOutput + ",";
            Console.ReadLine();
            return Json(number.Substring(0, number.Length - 1));
        }
        public void booksCountJs()
        {
            string lbid = Request.Form["lbid"];
            boper.booksCountJs(lbid, ((DomainModel.cmsuser)Session["cmsuser"]).id);
        }
        public JsonResult saveisbn()
        {

            string id = Request.Form["res"];
            string isbn = Request.Form["isbn"];
            if (boper.isbnCount(isbn) > 0) //有重复isbn
                return Json(0);
            else
            { 
                LibraryBookDetail _lbd = new LibraryBookDetail();
                if (_lbd.lbd_id == 0)
                {
                    _lbd.lbd_addTime = DateTime.Now;
                    _lbd.lbd_user = ((DomainModel.cmsuser)Session["cmsuser"]).id;
                    _lbd.lbd_state = (int)DAL.Enums.isbnstate.未借出;
                    _lbd.lbd_lbid = int.Parse(id);
                    _lbd.lbd_isbn = isbn;
                }
                else
                {
                    _lbd.lbd_lastUser = ((DomainModel.cmsuser)Session["cmsuser"]).id;
                    _lbd.lbd_addTime = _lbd.lbd_addTime.ToLocalTime();
                    _lbd.lbd_updateTime = DateTime.Now;
                }
                boper.save(_lbd);
            }
            return Json(1);
        }
        public JsonResult xjBook()
        {
            string id = Request.Form["res"];
            string state = Request.Form["state"];
            return Json(boper.updateBookState(int.Parse(id), int.Parse(state)));            
        }
        public JsonResult deleteLibraryBook()
        {
            int id = int.Parse(Request.Form["res"]);
            return Json(boper.deleteLibraryBook(id));
        }
        #endregion
        //
        //


        public ActionResult LibraryBookIndent()
        {
            return View();
        }
        public JsonResult getUserInfoByCard()
        {
            string name = Request.Form["name"];
            string nick = Request.Form["nick"];
            string card = Request.Form["card"];
            return Json(userOper.getUserInfoByCard(nick, name, card));
        }

        public JsonResult getLibraryBookIndent()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            string bookName = Request.Form["bookName"];
            string name = Request.Form["name"];
            int state = int.Parse(Request.Form["state"]);
            string in_s = Request.Form["in_s"];
            string in_e = Request.Form["in_e"];
            string card = Request.Form["card"];
            string isbn = Request.Form["isbn"];
            string indent = Request.Form["indent"];
            return Json(indentOper.getLibraryBookIndent(in_s, in_e, pageno, pagesize, state, card, isbn, indent, name, bookName));
            //return Json(indentOper.getLibraryBookIndent(in_s,
            //    in_e,
            //    pageno,
            //    pagesize,
            //    state,
            //    name,
            //    bookName,
            //    author,
            //    press));
        }

        public JsonResult getBooklist()
        {
            string name = Request.Form["name"];
            string author = Request.Form["author"];
            string isbn = Request.Form["isbn"];
            return Json(boper.getBooklist(name, author, isbn));
        }

        public ActionResult UserClass()
        {
            return View();
        }

        [ValidateInput(false)]
        public ActionResult saveUserClass()
        {
            DomainModel.UserClass _staff = new JavaScriptSerializer().Deserialize<DomainModel.UserClass>(Request.Form["UserClass"].ToString());
            _staff.uic_date = DateTime.Now;
            _staff.uic_user = ((DomainModel.cmsuser)Session["cmsuser"]).id;
            if(_staff.uic_id!=0)
                _staff.uic_date = _staff.uic_date.ToLocalTime();
            uOper.save(_staff);
            return Json(_staff);
        }

        //

        [ValidateInput(false)]
        public string saveLibraryBookIndent()
        {
            //DomainModel.LibraryBookIndent _staff = new JavaScriptSerializer().Deserialize<DomainModel.LibraryBookIndent>(Request.Form["LibraryBookIndent"].ToString());
            string lbid = Request.Form["lbid"];
            int uid =int.Parse(Request.Form["lbiuid"]);
            string[] arr = lbid.Split(',');//借几本书
            string str = bookRule.validationUser(uid, arr.Length);
            if (str == "best4")
                return "best4";//最多4本
            else if (str == "notimes")
                return "notimes";//无剩余次数
            else if (str == "nocard")
                return "nocard";
            else if (str == "erroruserrule")
                return "erroruserrule";
            else if (str == "erroruser")
                return "erroruser";
            else if (str.StartsWith("good"))
            {
                for (int i = 0; i < arr.Length; i++)
                {
                    int f = bookRule.validationBooks(int.Parse(arr[i].ToString()));
                    if (f == 2)
                        return "bdzs";//电子书不能进入订单流程
                    else if (f == 0)
                        return "bbcz";//图书不存在
                    else if (f == 1)
                        return "bnkc";//没有库存
                    else if (f == 4)//图书为下架或删除状态
                        return "bxj";
                }
                string[] arr1 = str.Split(',');
                IList list = indentOper.indent(lbid, System.Web.HttpContext.Current.Request.UserHostAddress, arr1[1].ToString(), uid);
                Hashtable hs = (Hashtable)list[0];
                if (hs["returns"].ToString() == "succe")
                    return "succe";
                else
                {
                    return hs["returns"].ToString().Substring(5, hs["returns"].ToString().Length);
                    //lose:徐测试第二,地图,徐测试
                }
                //_staff.lbi_ucid = int.Parse(arr1[1].ToString());
                //_staff.lbi_ip = System.Web.HttpContext.Current.Request.UserHostAddress;
                //_staff.lbi_time = DateTime.Now;
                //_staff.lbi_uid = user.u_id;
                //_staff.lbi_state = (int)DAL.Enums.lbistate.处理中;
                //bOper.save(_staff);
                //添加订单
            }
            else
                return "";
        }

        public JsonResult getUserClasslist()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            string classname = Request.Form["classname"];
            string teacher = Request.Form["teacher"];           
            string in_s = Request.Form["in_s"];
            string in_e = Request.Form["in_e"];
            return Json(uOper.getUserClasslist(classname,teacher,in_s,in_e,pageno,pagesize));
        }


        public JsonResult getUserClassbyid()
        {
            string id = Request.Form["res"];
            IList list = uOper.getUserClassbyid(int.Parse(id));
            if (list.Count > 0)
                return Json(list[0]);
            else
                return Json("");
        }

        public JsonResult deleteUserClass()
        {
            int id = int.Parse(Request.Form["res"]);
            return Json(uOper.deleteUserClass(id));
        }

        //
        public string getLibraryBookName()
        {
            int indentid = int.Parse(Request.Form["indentid"]);
            IList list = indentOper.getLibraryBookName(indentid);
            StringBuilder sb = new StringBuilder();
            if (list.Count > 0)
            {
                sb.Append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">");
                foreach (Hashtable hs in list)
                {
                    sb.Append("<tr>");
                    sb.Append("<td style=\"border:0px\">");
                    sb.Append(hs["lb_bookName"].ToString());
                    sb.Append("</td>");
                    sb.Append("</tr>");
                }
                sb.Append("</table>");
            }
            return sb.ToString();
        }


        public ActionResult checkClassName()
        {
            string className = Request.Form["className"];
            int id = Request.Form["id"] == null ? 0 : int.Parse(Request.Form["id"]);
            bool flag = uOper.checkClassName(className, id);
            if (flag)
                return Json(1);
            else
                return Json(0);
        }

        public string updateIndentState()
        {
            string id = Request.Form["id"];// == null ? 0 : int.Parse(Request.Form["id"]);
            int oldState = Request.Form["oldState"] == null ? 0 : int.Parse(Request.Form["oldState"]);
            int state = Request.Form["state"] == null ? 0 : int.Parse(Request.Form["state"]);
            IList list=indentOper.ReturnBook(id,state,oldState,((DomainModel.cmsuser)Session["cmsuser"]).id);
            Hashtable hs = (Hashtable)list[0];
            return hs["returns"].ToString();
            //if (state == (int)DAL.Enums.lbistate.订单已经撤销 || state == (int)DAL.Enums.lbistate.已归还)
            //{
            //    IList list = boper.getBookDetailId(id);
            //    foreach (Hashtable tb in list)
            //    {
            //        IList list1 = boper.getLibraryBookId(int.Parse(tb["lbid_lbdid"].ToString()));
            //        Hashtable hs = (Hashtable)list1[0];
            //        boper.addInventOry(int.Parse(hs["lbd_lbid"].ToString()));//撤消订单和归还的把图书库存量+1
            //        //修改该订单下的图书明细状态为未借出
            //        boper.updateIsbnBookState(int.Parse(tb["lbid_lbdid"].ToString()), (int)DAL.Enums.isbnstate.未借出);
            //    }
            //    //joy.LibraryBookDetail
            //}
            //indentOper.updateIndentState(id, state);
            //DomainModel.IndentOperationLog log = new DomainModel.IndentOperationLog();
            //log.iol_iblid = id;
            //log.iol_nowState = (byte)state;
            //log.iol_oldState = (byte)oldState;
            //log.iol_time = DateTime.Now;
            //log.iol_user = ((DomainModel.cmsuser)Session["cmsuser"]).id;
            //logOper.save(log);
            //return Json(1);
        }
    }
}
